<?php

namespace App\Remote\XiaoKe;

use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpFoundation\Request as RequestAlias;

class CustomerRemote extends Remote
{
    /**
     * 客户列表
     *
     * @param string $startDatetime
     * @param string $endDatetime
     * @param int $pageNum
     * @param int $pageSize
     * @return mixed
     * @throws GuzzleException
     * @throws ValidationException
     */
    public static function list(string $startDatetime, string $endDatetime, int $pageNum = 1, int $pageSize = 100)
    {
        return self::customRequestV3(
            "/api/services/1_0/rest/customer/list",
            RequestAlias::METHOD_POST,
            [
                "wid"            => self::getWid(),
                "pid"            => self::getPid(),
                "resourcesScope" => 5,
                "type"           => 2,
                "orderByApiName" => "s_create_time",
                "orderByRule"    => 1,
                "keyApiName"     => "c_xinxilaiyuan",
                "keyword"        => "抖音",
                "screenList"     => [
                    [
                        "apiName"    => "s_create_time",
                        "fieldType"  => 7,
                        "beginValue" => $startDatetime,
                        "endValue"   => $endDatetime,
                        "valueList"  => [
                            "99"
                        ]
                    ]
                ],
                "pageSize"       => $pageSize
            ],
            null,
            null,
            0,
            true
        );
    }


    /**
     * 获取客户详情
     *
     * @param string $key
     * @return mixed
     * @throws GuzzleException
     * @throws ValidationException
     */
    public static function detail(string $key)
    {
        return self::customRequestV3(
            "/api/services/1_0/rest/customer/detail",
            RequestAlias::METHOD_POST,
            [
                "wid" => self::getWid(),
                "pid" => self::getPid(),
                "key" => $key
            ],
            null,
            null,
            0,
            true
        );
    }

    public static function areas()
    {
        return self::customRequestV3(
            "/api/services/1_0/rest/dict/areaTree",
            RequestAlias::METHOD_POST,
            [
                "pid" => self::getPid(),
            ],
            null,
            null,
            0,
            true
        );
    }

    /**
     * 获取阶段下拉数据
     *
     * @return mixed
     * @throws GuzzleException
     * @throws ValidationException
     */
    public static function stageList()
    {
        return self::customRequestV3(
            "/api/services/1_0/rest/customer/stageList",
            RequestAlias::METHOD_POST,
            [
                "wid" => self::getWid(),
                "pid" => self::getPid(),
            ],
            null,
            null,
            30 * 60,
            true
        );
    }
}
